package com.example.barcodeapp.adapter.gatheradapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.barcodeapp.R;
import com.example.barcodeapp.common.Constants;
import com.example.barcodeapp.ui.home.bean.JiaoShiLeiBiaoBean;

import java.util.List;

public class AdapterMianFei extends RecyclerView.Adapter<AdapterMianFei.ViewHolder> {
    Context context;

    public AdapterMianFei(Context context) {
        this.context = context;
    }

    public List<JiaoShiLeiBiaoBean.DataEntity.KechengEntity> list;
    private AdapterMianFei.IClick callback;

    public void setCallback(IClick callback) {
        this.callback = callback;
    }

    public AdapterMianFei(Context context, List<JiaoShiLeiBiaoBean.DataEntity.KechengEntity> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.adapter_mianfei, parent, false);
        return new ViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Glide.with(context).load(Constants.Base_TPUrl2 +list.get(position).getImageurl()).into(holder.mianfeiIv);
        holder.textView2.setText(list.get(position).getCoursename());
        holder.textView3.setText(list.get(position).getDesc());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                callback.click(position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }


    public class ViewHolder extends RecyclerView.ViewHolder {
        private ImageView mianfeiIv;
        private TextView textView2;
        private TextView textView3;
        private TextView textView4;
        private TextView textView5;
        private TextView textView6;
        private TextView textView7;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            mianfeiIv = (ImageView) itemView.findViewById(R.id.mianfei_iv);
            textView2 = (TextView) itemView.findViewById(R.id.textView2);
            textView3 = (TextView) itemView.findViewById(R.id.textView3);
            textView4 = (TextView) itemView.findViewById(R.id.textView4);
            textView5 = (TextView) itemView.findViewById(R.id.textView5);
            textView6 = (TextView) itemView.findViewById(R.id.textView6);
            textView7 = (TextView) itemView.findViewById(R.id.textView7);
        }
    }
    public interface IClick {

        void click(int pos);

    }
}
